package com.dddd.blog.blogcommon.utils;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 集合有关操作
 * @author 喵星球的大橘
 */
public class CollectionUtils <T,S>{


    /**
     * 将 {S}类型的集合转化为{T}类型的集合
     * @param list
     * @param clazz
     * @param <T>
     * @return
     */
    public static <T,S> List<T> collectionInvert(List<S> list,Class<T> clazz) throws ClassNotFoundException {
        List<T> result = null;
        try{
            if(list!=null){
                result = list.stream()
                        .map(item -> ObjectInvertUtils.invert(item, clazz))
                        .collect(Collectors.toList());
            }
        }catch (ClassCastException e){
            System.out.println(e.getMessage());
        }
        return result;
    }

}
